package servlet.d_bank;

import java.io.IOException;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.d_bank.D_BizServiceImpl;
import dao.impl.d_bank.D_BizDaoImpl;
import entity.d_bank.Page;
import entity.d_bank.d_basicuser;

/**
 * Servlet implementation class SpageServlet
 */
public class SpageServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public SpageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
    }

    /**
     * @see Servlet#destroy()
     */
    public void destroy() {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        // TODO Auto-generated method stub
        String currentpage = request.getParameter("currentpage");// 获取当前页参数

        D_BizDaoImpl bdi = new D_BizDaoImpl();
        D_BizServiceImpl bzi = new D_BizServiceImpl();
        bzi.setD_bizdao(bdi);// 注入

        int count = bzi.getsum();// 获取oo返回的值
        Page pg = new Page();
        pg.setLastpage(count);// 设置尾页的数是2
        pg.setCurrentpage(Integer.valueOf(currentpage));// 设置当前页的值

        List<d_basicuser> listproduct = bzi.getNewsInfoPageById(pg);
        HttpSession session = request.getSession(false);
        session.setAttribute("listproduct", listproduct);
        session.setAttribute("pg", pg);
        response.sendRedirect("sl_store/essentialAccount.jsp");
        // request.getRequestDispatcher("sl_store/essentialAccount.jsp").forward(request,
        // response);
    }

}
